package com.qf.controller;

import com.qf.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class UserController {

    @GetMapping("/login")
    public String login(String name, HttpServletRequest request) {
        if ("admin".equals(name) || "qfAdmin".equals(name)) {
            request.getSession().setAttribute("login-user", new User(name,""));
            return "欢迎【"+name+"】:"+System.currentTimeMillis();
        } else {
            return "用户名获密码错误";
        }
    }

    @GetMapping("/findUser")
    public String findUser(HttpServletRequest request,HttpSession session2) {
        HttpSession session = request.getSession();
        Object attribute = session.getAttribute("login-user");
        System.out.println("session:"+session.getClass());
        System.out.println("session2:"+session2.getClass());
        System.out.println("session2获取值:"+session2.getAttribute("login-user"));

        return "登录用户【" + attribute + "】"+System.currentTimeMillis();
    }
}
